package  org.fantasy.cpp.core.bean;

import java.util.HashMap;
import java.util.Map;

public class ParamContextImpl implements ParamContext {

    private Map<String, String> param = new HashMap<String, String>();
    
    public ParamContextImpl(){
        
    }

    public void set(String key, String value) {
        param.put(key, value);
    }
    
    /**
    * 取得值
    * @param key
    * @return
     */
    public String get(String key) {
        String value = param.get(key);
        return (value != null ? value : "");
    }
    
    /**
     * 是否True
     * @param key
     * @return
     */
    public boolean isTrue(String key) {
        String value = get(key);
        return "1".equals(value) || "true".equalsIgnoreCase(value);
    }
    
    /**
     * 是否False
     * @param key
     * @return
     */
    public boolean isFalse(String key) {
        return !isTrue(key);
    }
    
    /**
     * 是否有效
     * @param key
     * @return
     */
    public boolean isValid(String key) {
        String value = get(key);
        return value.length() > 0;
    }

	@Override
	public String toString() {
		return param.toString();
	}
}